package com.topisv.tms.repository.stock.instorageNew;

import java.util.List;

import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;

import com.topisv.tms.entity.receiptDetail.ReceiptDetail;
import com.topisv.tms.entity.stock.instorage.InstorageUpTask;

public interface ReceiptDetailDao extends PagingAndSortingRepository<ReceiptDetail, Long>, JpaSpecificationExecutor<ReceiptDetail> {
	@Query("select t from ReceiptDetail t where   t.billCode=?1 and t.lpnNo=?2 and t.unUpNum>0 and t.status not in ('3') order by id")
	List<ReceiptDetail> getUnUpDetailByLPN(String billCode,String lpn);
	@Query("select t from ReceiptDetail t where   t.billCode=?1 and t.lpnNo=?2 and t.status in ('1','2') order by id")
	List<ReceiptDetail> getUpDetailByLPN(String billCode,String lpn);
	
	@Query("select t from ReceiptDetail t where   t.lpnNo=?1 and t.unUpNum>0 and t.status not in ('3') order by id")
	List<ReceiptDetail> getUnUpDetailByLPN(String lpn);
	@Query("select t from ReceiptDetail t where   t.lpnNo=?1 and t.status in ('1','2') order by id")
	List<ReceiptDetail> getUpDetailByLPN(String lpn);
	
	
	@Query("select t from ReceiptDetail t where t.billCode=?1 and t.lpnNo=?2 and t.sku=?3 and t.status in ('0','1')")
	ReceiptDetail loadByReceiptDetail(String billCode,String lpn,String sku);
	
	@Query("select t from ReceiptDetail t where t.billCode=?1 and t.lpnNo=?2 and t.sku=?3 and t.batchCode = ?4 and "
	    + "t.productDate = ?5 and t.expireDate = ?6 and t.status in ('0','1')")
    ReceiptDetail loadByReceiptDetailNew(String billCode,String lpn,String sku, String batchCode, String productDate, String expireDate);
	
	@Query("select t from ReceiptDetail t where   t.billCode=?1 and t.lpnNo=?2 and t.sku<>?3 and t.status in ('0','1') order by id")
	List<ReceiptDetail> getLPNOtherSkuUnUp(String billCode,String lpn,String sku);
	
	@Query("select t from ReceiptDetail t where   t.billCode=?1 and t.lpnNo=?2 and t.sku<>?3 and t.batchCode = ?4 and "
	    + "t.productDate = ?5 and t.expireDate = ?6 and t.status in ('0','1') order by id")
    List<ReceiptDetail> getLPNOtherSkuUnUpNew(String billCode,String lpn,String sku, String batchCode, String productDate, String expireDate);
	
	@Modifying
	@Query("update ReceiptDetail set printFlag='1' where id in (?1) ")
	void updateReceiptDetailPrintFlag(List<Long> ids);

}
